package impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import common.ConnectDB;

import dao.OrderDetailDao;
import entity.OrderDetail;

public class OrderDetailImpl implements OrderDetailDao {
	
	public boolean add(OrderDetail order_detail)
	{
		Connection con = ConnectDB.getConnection();
		PreparedStatement ps = null;
		String sql = "insert into order_detail values(?,?,?,?,?,?)";
		try {
			ps = con.prepareStatement(sql);
			ps.setString(1, order_detail.getOrder_id());
			ps.setInt(2, order_detail.getRnum());
			ps.setInt(3, order_detail.getBookId());
			ps.setString(4, order_detail.getBookName());
			ps.setFloat(5, order_detail.getPrice());
			ps.setInt(6, order_detail.getBuy_number());
			
			if(ps.executeUpdate()>0)
				return true;
			else
				return false;
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			try {
				ps.close();
				con.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return false;
		
	}
	
}
